Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
b6b11c7
Rejig some top-level `rustc_hir_pretty` functions.
nnethercote Oct 10, 2023
51e8c80
Add unstable book page for the no-jump-tables codegen option
tgross35 Oct 10, 2023
664b185
Remove many unneeded `pub`s.
nnethercote Oct 10, 2023
494bc85
Tweak comments.
nnethercote Oct 10, 2023
7d35902
Fiddle with `State` functions.
nnethercote Oct 10, 2023
232aaeb
Handle several `#[diagnostic::on_unimplemented]` attributes correctly
weiznich Oct 11, 2023
a7ae2a6
coverage: Simplify the detection of reloop edges to be given expressions
Zalathar Oct 12, 2023
d1920c5
coverage: Rename `next_bcb` to just `bcb`
Zalathar Oct 12, 2023
ea3fb7b
coverage: Use a `VecDeque` for loop traversal worklists
Zalathar Oct 12, 2023
15360b3
coverage: Store a graph reference in the graph traversal struct
Zalathar Oct 11, 2023
59f4f1c
coverage: Don't store loop backedges in the traversal context
Zalathar Oct 11, 2023
d99ab97
coverage: Simplify adding BCB successors to the traversal worklists
Zalathar Oct 12, 2023
8309097
Fix mips platform support entries.
ehuss Oct 12, 2023
54c528e
Rollup merge of #116593 - tgross35:no-jump-tables-docs, r=compiler-er…
matthiaskrgr Oct 12, 2023
4b1867a
Rollup merge of #116625 - nnethercote:rustc_hir_pretty, r=fee1-dead
matthiaskrgr Oct 12, 2023
5f90bee
Rollup merge of #116642 - weiznich:diagnostic_on_unimplemented_improv…
matthiaskrgr Oct 12, 2023
4832811
Rollup merge of #116654 - Zalathar:reloop-traversal, r=oli-obk
matthiaskrgr Oct 12, 2023
6ccc521
Rollup merge of #116669 - ehuss:fix-platform-table, r=nikic
matthiaskrgr Oct 12, 2023
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
Prev Previous commit
Next Next commit
Handle several #[diagnostic::on_unimplemented] attributes correctly
This PR fixes an issues where rustc would ignore subsequent
`#[diagnostic::on_unimplemented]` attributes. The [corresponding
RFC](https://rust-lang.github.io/rfcs/3368-diagnostic-attribute-namespace.html)
specifies that the first matching instance of each option is used.
Invalid attributes are linted and otherwise ignored.
  • Loading branch information
weiznich committed Oct 11, 2023
commit 232aaeba7c6779233659b0a57ed75a5d7a48cfb0
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{ObligationCauseCode, PredicateObligation};
use crate::infer::error_reporting::TypeErrCtxt;
use rustc_ast::{MetaItem, NestedMetaItem};
use rustc_ast::{Attribute, MetaItem, NestedMetaItem};
use rustc_attr as attr;
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{struct_span_err, ErrorGuaranteed};
Expand Down Expand Up @@ -474,18 +474,40 @@ impl<'tcx> OnUnimplementedDirective {
}

pub fn of_item(tcx: TyCtxt<'tcx>, item_def_id: DefId) -> Result<Option<Self>, ErrorGuaranteed> {
let mut is_diagnostic_namespace_variant = false;
let Some(attr) = tcx.get_attr(item_def_id, sym::rustc_on_unimplemented).or_else(|| {
if tcx.features().diagnostic_namespace {
is_diagnostic_namespace_variant = true;
tcx.get_attrs_by_path(item_def_id, &[sym::diagnostic, sym::on_unimplemented]).next()
} else {
None
}
}) else {
return Ok(None);
};
if let Some(attr) = tcx.get_attr(item_def_id, sym::rustc_on_unimplemented) {
return Self::parse_attribute(attr, false, tcx, item_def_id);
} else if tcx.features().diagnostic_namespace {
tcx.get_attrs_by_path(item_def_id, &[sym::diagnostic, sym::on_unimplemented])
.filter_map(|attr| Self::parse_attribute(attr, true, tcx, item_def_id).transpose())
.try_fold(None, |aggr: Option<Self>, directive| {
let directive = directive?;
if let Some(aggr) = aggr {
let mut subcommands = aggr.subcommands;
subcommands.extend(directive.subcommands);
Ok(Some(Self {
condition: aggr.condition.or(directive.condition),
subcommands,
message: aggr.message.or(directive.message),
label: aggr.label.or(directive.label),
note: aggr.note.or(directive.note),
parent_label: aggr.parent_label.or(directive.parent_label),
append_const_msg: aggr.append_const_msg.or(directive.append_const_msg),
}))
} else {
Ok(Some(directive))
}
})
} else {
Ok(None)
}
}

fn parse_attribute(
attr: &Attribute,
is_diagnostic_namespace_variant: bool,
tcx: TyCtxt<'tcx>,
item_def_id: DefId,
) -> Result<Option<Self>, ErrorGuaranteed> {
let result = if let Some(items) = attr.meta_item_list() {
Self::parse(tcx, item_def_id, &items, attr.span, true, is_diagnostic_namespace_variant)
} else if let Some(value) = attr.value_str() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#![feature(diagnostic_namespace)]

#[diagnostic::on_unimplemented(
//~^WARN malformed `on_unimplemented` attribute
//~|WARN malformed `on_unimplemented` attribute
if(Self = ()),
message = "not used yet",
label = "not used yet",
note = "not used yet"
)]
#[diagnostic::on_unimplemented(message = "fallback!!")]
#[diagnostic::on_unimplemented(label = "fallback label")]
#[diagnostic::on_unimplemented(note = "fallback note")]
#[diagnostic::on_unimplemented(message = "fallback2!!")]
trait Foo {}

fn takes_foo(_: impl Foo) {}

fn main() {
takes_foo(());
//~^ERROR fallback!!
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
warning: malformed `on_unimplemented` attribute
--> $DIR/ignore_unsupported_options_and_continue_to_use_fallback.rs:3:1
|
LL | / #[diagnostic::on_unimplemented(
LL | |
LL | |
LL | | if(Self = ()),
... |
LL | | note = "not used yet"
LL | | )]
| |__^
|
= note: `#[warn(unknown_or_malformed_diagnostic_attributes)]` on by default

warning: malformed `on_unimplemented` attribute
--> $DIR/ignore_unsupported_options_and_continue_to_use_fallback.rs:3:1
|
LL | / #[diagnostic::on_unimplemented(
LL | |
LL | |
LL | | if(Self = ()),
... |
LL | | note = "not used yet"
LL | | )]
| |__^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error[E0277]: fallback!!
--> $DIR/ignore_unsupported_options_and_continue_to_use_fallback.rs:20:15
|
LL | takes_foo(());
| --------- ^^ fallback label
| |
| required by a bound introduced by this call
|
= help: the trait `Foo` is not implemented for `()`
= note: fallback note
help: this trait has no implementations, consider adding one
--> $DIR/ignore_unsupported_options_and_continue_to_use_fallback.rs:15:1
|
LL | trait Foo {}
| ^^^^^^^^^
note: required by a bound in `takes_foo`
--> $DIR/ignore_unsupported_options_and_continue_to_use_fallback.rs:17:22
|
LL | fn takes_foo(_: impl Foo) {}
| ^^^ required by this bound in `takes_foo`

error: aborting due to previous error; 2 warnings emitted

For more information about this error, try `rustc --explain E0277`.