Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #83134

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2f7672f
run-make: Specify --target to rustc
tblah Jan 9, 2021
1b55654
run-make: skip issue-36710 on riscv64
tblah Jan 11, 2021
f69d954
ci: docker: riscv64gc: specify host explicitly
tblah Feb 20, 2021
b71573b
bootstrap: don't run linkcheck when crosscompiling
tblah Feb 21, 2021
9b23df1
ci: docker: x86_64: specify host explicitly
tblah Feb 21, 2021
1ba71ab
Inline Attribute::has_name
tmiasko Mar 11, 2021
4943190
Validate rustc_layout_scalar_valid_range_{start,end} attributes
tmiasko Mar 11, 2021
c74fdf0
More precise spans for HIR paths
petrochenkov Mar 13, 2021
9613a88
Refactor `check_doc_attrs` body
camelid Mar 13, 2021
7189c05
Lint non-meta doc attributes
camelid Mar 13, 2021
7e972a3
Report error for each invalid nested attribute
camelid Mar 11, 2021
fe64970
Add another test case
camelid Mar 12, 2021
5134047
Add hyphen to "crate level"
camelid Mar 13, 2021
13884dc
Update `rustdoc-ui` versions of the `doc-attr` test
camelid Mar 14, 2021
e161a2f
Remove unused `opt_local_def_id_to_hir_id` function
jyn514 Mar 14, 2021
71a784d
Fix a typo in `swap_nonoverlapping_bytes`
hiyoko3m Mar 12, 2021
5ec0540
Fix a typo in thread_local_dtor.rs
hiyoko3m Mar 14, 2021
6ddd840
Minor refactoring in try_index_step
osa1 Mar 14, 2021
14038c7
Remove duplicate asserts, replace eq assert with assert_eq
osa1 Mar 14, 2021
13076f9
Tweak diagnostics
camelid Mar 14, 2021
8f40e11
Use pretty-printer instead of `span_to_snippet`
camelid Mar 14, 2021
7429c68
Don't encode file information for span with a dummy location
Aaron1011 Mar 14, 2021
e783c0d
Rollup merge of #80839 - tblah:riscv64linux_links, r=Mark-Simulacrum
Dylan-DPC Mar 15, 2021
e8a22e8
Rollup merge of #83054 - tmiasko:rustc_layout_scalar_valid_range, r=d…
Dylan-DPC Mar 15, 2021
42b856e
Rollup merge of #83092 - petrochenkov:qspan, r=estebank
Dylan-DPC Mar 15, 2021
cbbf2d4
Rollup merge of #83098 - camelid:more-doc-attr-check, r=davidtwco
Dylan-DPC Mar 15, 2021
51e6acf
Rollup merge of #83108 - jyn514:remove-unused, r=estebank
Dylan-DPC Mar 15, 2021
7fcef79
Rollup merge of #83110 - hyksm:fix-typo, r=jonas-schievink
Dylan-DPC Mar 15, 2021
9360930
Rollup merge of #83113 - osa1:refactor_try_index_step, r=jonas-schievink
Dylan-DPC Mar 15, 2021
32829fc
Rollup merge of #83132 - Aaron1011:fix/incr-cache-dummy, r=estebank
Dylan-DPC Mar 15, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4265,6 +4265,7 @@ name = "rustc_passes"
version = "0.0.0"
dependencies = [
"rustc_ast",
"rustc_ast_pretty",
"rustc_attr",
"rustc_data_structures",
"rustc_errors",
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,17 @@ impl PathSegment {
pub fn from_ident(ident: Ident) -> Self {
PathSegment { ident, id: DUMMY_NODE_ID, args: None }
}

pub fn path_root(span: Span) -> Self {
PathSegment::from_ident(Ident::new(kw::PathRoot, span))
}

pub fn span(&self) -> Span {
match &self.args {
Some(args) => self.ident.span.to(args.span()),
None => self.ident.span,
}
}
}

/// The arguments of a path segment.
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_ast/src/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ impl NestedMetaItem {
}

impl Attribute {
#[inline]
pub fn has_name(&self, name: Symbol) -> bool {
match self.kind {
AttrKind::Normal(ref item, _) => item.path == name,
Expand Down
13 changes: 8 additions & 5 deletions compiler/rustc_ast_lowering/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let partial_res =
self.resolver.get_partial_res(id).unwrap_or_else(|| PartialRes::new(Res::Err));

let path_span_lo = p.span.shrink_to_lo();
let proj_start = p.segments.len() - partial_res.unresolved_segments();
let path = self.arena.alloc(hir::Path {
res: self.lower_res(partial_res.base_res()),
Expand Down Expand Up @@ -108,7 +109,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
)
},
)),
span: p.span,
span: p.segments[..proj_start]
.last()
.map_or(path_span_lo, |segment| path_span_lo.to(segment.span())),
});

// Simple case, either no projections, or only fully-qualified.
Expand All @@ -127,7 +130,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// e.g., `Vec` in `Vec::new` or `<I as Iterator>::Item` in
// `<I as Iterator>::Item::default`.
let new_id = self.next_id();
self.arena.alloc(self.ty_path(new_id, p.span, hir::QPath::Resolved(qself, path)))
self.arena.alloc(self.ty_path(new_id, path.span, hir::QPath::Resolved(qself, path)))
};

// Anything after the base path are associated "extensions",
Expand All @@ -141,7 +144,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// 3. `<<std::vec::Vec<T>>::IntoIter>::Item`
// * final path is `<<<std::vec::Vec<T>>::IntoIter>::Item>::clone`
for (i, segment) in p.segments.iter().enumerate().skip(proj_start) {
let segment = self.arena.alloc(self.lower_path_segment(
let hir_segment = self.arena.alloc(self.lower_path_segment(
p.span,
segment,
param_mode,
Expand All @@ -150,7 +153,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
itctx.reborrow(),
None,
));
let qpath = hir::QPath::TypeRelative(ty, segment);
let qpath = hir::QPath::TypeRelative(ty, hir_segment);

// It's finished, return the extension of the right node type.
if i == p.segments.len() - 1 {
Expand All @@ -159,7 +162,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {

// Wrap the associated extension in another type node.
let new_id = self.next_id();
ty = self.arena.alloc(self.ty_path(new_id, p.span, qpath));
ty = self.arena.alloc(self.ty_path(new_id, path_span_lo.to(segment.span()), qpath));
}

// We should've returned in the for loop above.
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_hir/src/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,6 @@ impl Definitions {
self.def_id_to_hir_id[id].unwrap()
}

#[inline]
pub fn opt_local_def_id_to_hir_id(&self, id: LocalDefId) -> Option<hir::HirId> {
self.def_id_to_hir_id[id]
}

#[inline]
pub fn opt_hir_id_to_local_def_id(&self, hir_id: hir::HirId) -> Option<LocalDefId> {
self.hir_id_to_def_id.get(&hir_id).copied()
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1809,7 +1809,7 @@ impl<'hir> QPath<'hir> {
pub fn span(&self) -> Span {
match *self {
QPath::Resolved(_, path) => path.span,
QPath::TypeRelative(_, ps) => ps.ident.span,
QPath::TypeRelative(qself, ps) => qself.span.to(ps.ident.span),
QPath::LangItem(_, span) => span,
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/traits/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub fn report_object_safety_error(
<https://doc.rust-lang.org/reference/items/traits.html#object-safety>",
);

if tcx.sess.trait_methods_not_found.borrow().contains(&span) {
if tcx.sess.trait_methods_not_found.borrow().iter().any(|full_span| full_span.contains(span)) {
// Avoid emitting error caused by non-existing method (#58734)
err.cancel();
}
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_middle/src/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,6 @@ impl<'hir> Map<'hir> {
self.tcx.definitions.local_def_id_to_hir_id(def_id)
}

#[inline]
pub fn opt_local_def_id_to_hir_id(&self, def_id: LocalDefId) -> Option<HirId> {
self.tcx.definitions.opt_local_def_id_to_hir_id(def_id)
}

pub fn iter_local_def_id(&self) -> impl Iterator<Item = LocalDefId> + '_ {
self.tcx.definitions.iter_local_def_id()
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/ty/query/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,12 +1045,12 @@ where
E: 'a + OpaqueEncoder,
{
fn encode(&self, s: &mut CacheEncoder<'a, 'tcx, E>) -> Result<(), E::Error> {
if *self == DUMMY_SP {
let span_data = self.data();
if self.is_dummy() {
TAG_PARTIAL_SPAN.encode(s)?;
return SyntaxContext::root().encode(s);
return span_data.ctxt.encode(s);
}

let span_data = self.data();
let pos = s.source_map.byte_pos_to_line_and_col(span_data.lo);
let partial_span = match &pos {
Some((file_lo, _, _)) => !file_lo.contains(span_data.hi),
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_mir_build/src/build/expr/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
block.unit()
}
ExprKind::Index { .. } | ExprKind::Deref { .. } | ExprKind::Field { .. } => {
debug_assert!(Category::of(&expr.kind) == Some(Category::Place));
debug_assert_eq!(Category::of(&expr.kind), Some(Category::Place));

// Create a "fake" temporary variable so that we check that the
// value is Sized. Usually, this is caught in type checking, but
Expand All @@ -436,8 +436,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
this.local_decls.push(LocalDecl::new(expr.ty, expr.span));
}

debug_assert!(Category::of(&expr.kind) == Some(Category::Place));

let place = unpack!(block = this.as_place(block, expr));
let rvalue = Rvalue::Use(this.consume_by_copy_or_move(place));
this.cfg.push_assign(block, source_info, destination, rvalue);
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_passes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ rustc_serialize = { path = "../rustc_serialize" }
rustc_span = { path = "../rustc_span" }
rustc_trait_selection = { path = "../rustc_trait_selection" }
rustc_lexer = { path = "../rustc_lexer" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
147 changes: 100 additions & 47 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_middle::hir::map::Map;
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::TyCtxt;

use rustc_ast::{Attribute, LitKind, NestedMetaItem};
use rustc_ast::{Attribute, Lit, LitKind, NestedMetaItem};
use rustc_errors::{pluralize, struct_span_err};
use rustc_hir as hir;
use rustc_hir::def_id::LocalDefId;
Expand Down Expand Up @@ -87,6 +87,10 @@ impl CheckAttrVisitor<'tcx> {
self.check_export_name(hir_id, &attr, span, target)
} else if self.tcx.sess.check_name(attr, sym::rustc_args_required_const) {
self.check_rustc_args_required_const(&attr, span, target, item)
} else if self.tcx.sess.check_name(attr, sym::rustc_layout_scalar_valid_range_start) {
self.check_rustc_layout_scalar_valid_range(&attr, span, target)
} else if self.tcx.sess.check_name(attr, sym::rustc_layout_scalar_valid_range_end) {
self.check_rustc_layout_scalar_valid_range(&attr, span, target)
} else if self.tcx.sess.check_name(attr, sym::allow_internal_unstable) {
self.check_allow_internal_unstable(hir_id, &attr, span, target, &attrs)
} else if self.tcx.sess.check_name(attr, sym::rustc_allow_const_fn_unstable) {
Expand Down Expand Up @@ -520,7 +524,7 @@ impl CheckAttrVisitor<'tcx> {
.struct_span_err(
meta.span(),
&format!(
"`#![doc({} = \"...\")]` isn't allowed as a crate level attribute",
"`#![doc({} = \"...\")]` isn't allowed as a crate-level attribute",
attr_name,
),
)
Expand All @@ -531,79 +535,97 @@ impl CheckAttrVisitor<'tcx> {
}

fn check_doc_attrs(&self, attr: &Attribute, hir_id: HirId, target: Target) -> bool {
if let Some(mi) = attr.meta() {
if let Some(list) = mi.meta_item_list() {
for meta in list {
if meta.has_name(sym::alias) {
if !self.check_attr_crate_level(meta, hir_id, "alias")
|| !self.check_doc_alias(meta, hir_id, target)
let mut is_valid = true;

if let Some(list) = attr.meta().and_then(|mi| mi.meta_item_list().map(|l| l.to_vec())) {
for meta in list {
if let Some(i_meta) = meta.meta_item() {
match i_meta.name_or_empty() {
sym::alias
if !self.check_attr_crate_level(&meta, hir_id, "alias")
|| !self.check_doc_alias(&meta, hir_id, target) =>
{
return false;
is_valid = false
}
} else if meta.has_name(sym::keyword) {
if !self.check_attr_crate_level(meta, hir_id, "keyword")
|| !self.check_doc_keyword(meta, hir_id)

sym::keyword
if !self.check_attr_crate_level(&meta, hir_id, "keyword")
|| !self.check_doc_keyword(&meta, hir_id) =>
{
return false;
is_valid = false
}
} else if meta.has_name(sym::test) {
if CRATE_HIR_ID != hir_id {

sym::test if CRATE_HIR_ID != hir_id => {
self.tcx.struct_span_lint_hir(
INVALID_DOC_ATTRIBUTES,
hir_id,
meta.span(),
|lint| {
lint.build(
"`#![doc(test(...)]` is only allowed as a crate level attribute"
"`#![doc(test(...)]` is only allowed \
as a crate-level attribute",
)
.emit();
},
);
return false;
is_valid = false;
}
} else if let Some(i_meta) = meta.meta_item() {
if ![
sym::cfg,
sym::hidden,
sym::html_favicon_url,
sym::html_logo_url,
sym::html_no_source,
sym::html_playground_url,
sym::html_root_url,
sym::include,
sym::inline,
sym::issue_tracker_base_url,
sym::masked,
sym::no_default_passes, // deprecated
sym::no_inline,
sym::passes, // deprecated
sym::plugins, // removed, but rustdoc warns about it itself
sym::primitive,
sym::spotlight,
sym::test,
]
.iter()
.any(|m| i_meta.has_name(*m))
{

// no_default_passes: deprecated
// passes: deprecated
// plugins: removed, but rustdoc warns about it itself
sym::alias
| sym::cfg
| sym::hidden
| sym::html_favicon_url
| sym::html_logo_url
| sym::html_no_source
| sym::html_playground_url
| sym::html_root_url
| sym::include
| sym::inline
| sym::issue_tracker_base_url
| sym::keyword
| sym::masked
| sym::no_default_passes
| sym::no_inline
| sym::passes
| sym::plugins
| sym::primitive
| sym::spotlight
| sym::test => {}

_ => {
self.tcx.struct_span_lint_hir(
INVALID_DOC_ATTRIBUTES,
hir_id,
i_meta.span,
|lint| {
lint.build(&format!(
let msg = format!(
"unknown `doc` attribute `{}`",
i_meta.name_or_empty()
))
.emit();
rustc_ast_pretty::pprust::path_to_string(&i_meta.path),
);
lint.build(&msg).emit();
},
);
return false;
is_valid = false;
}
}
} else {
self.tcx.struct_span_lint_hir(
INVALID_DOC_ATTRIBUTES,
hir_id,
meta.span(),
|lint| {
lint.build(&format!("invalid `doc` attribute")).emit();
},
);
is_valid = false;
}
}
}
true

is_valid
}

/// Checks if `#[cold]` is applied to a non-function. Returns `true` if valid.
Expand Down Expand Up @@ -807,6 +829,37 @@ impl CheckAttrVisitor<'tcx> {
}
}

fn check_rustc_layout_scalar_valid_range(
&self,
attr: &Attribute,
span: &Span,
target: Target,
) -> bool {
if target != Target::Struct {
self.tcx
.sess
.struct_span_err(attr.span, "attribute should be applied to a struct")
.span_label(*span, "not a struct")
.emit();
return false;
}

let list = match attr.meta_item_list() {
None => return false,
Some(it) => it,
};

if matches!(&list[..], &[NestedMetaItem::Literal(Lit { kind: LitKind::Int(..), .. })]) {
true
} else {
self.tcx
.sess
.struct_span_err(attr.span, "expected exactly one integer literal argument")
.emit();
false
}
}

/// Checks if `#[rustc_legacy_const_generics]` is applied to a function and has a valid argument.
fn check_rustc_legacy_const_generics(
&self,
Expand Down
9 changes: 7 additions & 2 deletions compiler/rustc_typeck/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1413,8 +1413,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
name: Symbol,
) {
let mut err = struct_span_err!(self.tcx().sess, span, E0223, "ambiguous associated type");
if let (Some(_), Ok(snippet)) = (
self.tcx().sess.confused_type_with_std_module.borrow().get(&span),
if let (true, Ok(snippet)) = (
self.tcx()
.sess
.confused_type_with_std_module
.borrow()
.keys()
.any(|full_span| full_span.contains(span)),
self.tcx().sess.source_map().span_to_snippet(span),
) {
err.span_suggestion(
Expand Down
Loading